package com.core.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


/**
 * 
 * @author 
 * 取得Spring容器的上下文环境变量，必须配置在Spring配置文件中才能使用
 *
 */
public class AppUtil implements ApplicationContextAware{
	private static ApplicationContext  appContext=null;
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		appContext=applicationContext;
	}
	
	/**
	 * 按Id取得容器Bean中的实例
	 * @param beanId
	 * @return
	 */
	public static Object getById(String beanId){
		return appContext.getBean(beanId);
	}
}
